package zjs.dc.controller;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

/**
 * @Class:
 * @Author: guoml
 * @Description: 针对企查查t_ipo_company_important_sszc表和聚源LC_SuitArbitration表进行数据映射开发
 * @Date: 2021/12/7 12:51
 */

public class TIpoCompanyImportantSszc {
    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder().appName("t_ipo_company_important_sszc").enableHiveSupport().getOrCreate();
        spark.sparkContext().setLogLevel("ERROR");
        //获取中数增量数据表中的新增数据（left join）
        Dataset<Row> insert_data = spark.sql("SELECT md5(a.ID),\n" +
                "       b.SecuCode,\n" +
                "       a.InfoPublDate,\n" +
                "       a.SubjectMatterStat,\n" +
                "       a.EventContent,\n" +
                "       a.Plaintiff,\n" +
                "       a.Defendant,\n" +
                "       '' as litigation_type,\n" +
                "       a.LatestSuitSum,\n" +
                "       c.MS,\n" +
                "       '' as one_sue_date,\n" +
                "       '' as one_suecourt,\n" +
                "       '' as one_sentence_date,\n" +
                "       '' as one_sentence_content,\n" +
                "       '' as one_is_appeal,\n" +
                "       '' as two_prosecution,\n" +
                "       '' as two_court,\n" +
                "       '' as two_sentence_date,\n" +
                "       '' as two_sentence_content,\n" +
                "       d.MS,\n" +
                "       '' as created_date,\n" +
                "       '' as updated_date,\n" +
                "       '' as encrypt_key,\n" +
                "       regexp_replace(current_date(),'-',''),\n" +
                "       \"1\" as isadd\n" +
                "FROM\n" +
                "  a_dc_ep_ods.LC_SuitArbitration a\n" +
                "INNER JOIN\n" +
                "  (select * from a_dc_ep_ods.SecuMain where ListedState = 1 and SecuCategory = 1) b on a.CompanyCode = b.CompanyCode\n" +
                "LEFT JOIN\n" +
                "  (SELECT *\n" +
                "   FROM a_dc_ep_ods.CT_SystemConst m\n" +
                "   WHERE m.LB = 1068) c\n" +
                "ON a.CurrencyUnit = c.DM\n" +
                "LEFT JOIN\n" +
                "  (SELECT *\n" +
                "   FROM a_dc_ep_ods.CT_SystemConst m\n" +
                "   WHERE m.LB = 1058) d\n" +
                "ON a.AdjudgementStatus = d.DM");
        insert_data.createOrReplaceTempView("tmp_t_ipo_company_important_sszc1");
        spark.sql("insert overwrite table a_dc_ep_incr.t_ipo_company_important_sszc select * from tmp_t_ipo_company_important_sszc1");
        spark.stop();
    }
}
